#include <cmath>
#include <iostream>

#include "geometry_primitives.h"

namespace 
{
   int my_round(double d)
   {
      return (int) std::floor(d + 0.5);
   }
}
point::point(double x, double y): x(x), y(y)
{

}

point::point(): x(0), y(0)
{

}

int point::compare_to(const point& a) const
{
   if (my_round(x - a.x) != 0) 
   {
      return my_round(x - a.x);
   } 
   else
   {
      return my_round(y - a.y);
   }
}

bool point::operator ==(const point& a) const
{
   return compare_to(a) == 0;
}
bool point::operator !=(const point& a) const
{
   return compare_to(a) != 0;
}
bool point::operator >=(const point& a) const
{
   return compare_to(a) >= 0;
}
bool point::operator >(const point& a) const
{
   return compare_to(a) > 0;
}
bool point::operator <=(const point& a) const
{
   return compare_to(a) <= 0;
}
bool point::operator <(const point& a) const
{
   return compare_to(a) < 0;
}

segment::segment(point f, point s)
{
   if (f <= s) 
   {
      a = f;
      b = s;
   } else
   {
      a = s;
      b = f;
   }
}

std::istream& operator >>(std::istream& in, point& a) 
{
   in >> a.x >> a.y;
   return in;
}
std::ostream& operator <<(std::ostream& out, const point& a) 
{
   out << "(" << a.x << ", " << a.y << ")";
   return out;
}

std::istream& operator >>(std::istream& in, segment& a)
{
   in >> a.a >> a.b;
   return in;
}
std::ostream& operator <<(std::ostream& out, const segment& a) 
{
   out << "[" << a.a << ", " << a.b << "]"; 
   return out;
}